#include "Precompiled.h"
#include "EntityRenderManager.h"
#include "RTTI.h"

namespace Game {
namespace Common {

EntityRenderManager::EntityRenderManager() {
}

EntityRenderManager::~EntityRenderManager() {
}

IEntityRender* EntityRenderManager::GetEntityRender(const RTTI& rtti) const {
    EntityRenderMap::const_iterator it = this->entityRenderMap.find(rtti.GetClassName());
    if (it != this->entityRenderMap.end()) {
        return (*it).second;
    }

    return NULL;
}

void EntityRenderManager::Free() {
    EntityRenderMap::const_iterator it = this->entityRenderMap.begin();
    EntityRenderMap::const_iterator end = this->entityRenderMap.end();
    for (; it != end; ++it) {
        IEntityRender* entityRender = it->second;
        SAFE_DELETE(entityRender);
    }

    this->entityRenderMap.clear();
}

void EntityRenderManager::Register(IEntityRender* entityRender) {
    this->entityRenderMap.insert(EntityRenderMapPair(entityRender->GetEntityRTTI().GetClassName(), entityRender));
    entityRender->SetEntityRenderManager(this);
}

}
}